<template>
	<view class="container">
		<!-- <u-swiper
			class="home-banner"
			:list="bannerList"
			height="500"
			border-radius="0"
			@click="toPage"
		></u-swiper> -->
		<view class="contents">
			<scroll-view :enable-flex="true" scroll-y="true" class="content-container">
				<view v-for="(idiom, index) in idioms" :key="index" class="idiom" @click="copy(idiom.Name)">
					<view class="content">
						<text v-for="(w, i) in idiom.Name" :key="i"
							:style="{color: idiom.Index === i ? '#F44336' : '#333'}">
							{{w}}
						</text>
					</view>
					<!-- <view class="copy">
								<hm-copy-text value="长按复制" :copyValue="idiom.Name" color="transparent" :showCopyBtn="false"></hm-copy-text>
							</view> -->
				</view>
			</scroll-view>
			<scroll-view style="border-left: none;" :enable-flex="true" scroll-y="true" class="content-container">
				<view v-for="(idiom, index) in idioms2" :key="index" class="idiom" @click="copy(idiom.Name)">
					<view class="content">
						<text v-for="(w, i) in idiom.Name" :key="i"
							:style="{color: idiom.Index === i ? '#F44336' : '#333'}">
							{{w}}
						</text>
					</view>
					<!-- <view class="copy">
								<hm-copy-text value="长按复制" :copyValue="idiom.Name" color="transparent" :showCopyBtn="false"></hm-copy-text>
							</view> -->
				</view>
			</scroll-view>
		</view>

		<view class="title-tips">
			点击上方文案复制，直播时可用电脑版微信打开
		</view>
		<view class="inputs">
			<view class="input-box">
				<input class="input" placeholder="请输入姓氏" v-model="surname" />
				<text>姓氏1</text>
			</view>
			<view class="input-box">
				<input class="input" placeholder="请输入姓氏" v-model="surname2" />
				<text>姓氏2</text>
			</view>
		</view>
    
    <view class="title-tips" style="color: #FF6A60; margin-top: 200rpx;">
    	直接使用海米头像直播，更轻松省力
    </view>
    <view class="title-tips" style="color: #FF6A60; margin-top: 0rpx;">
      无需ps，手机也能直播
    </view>
		<view class="footer">
			<view class="share-btn">
				<hm-share :templateData="templateData" />
			</view>
			<button class="ss-reset-button generate-btn" @tap="getName">
				立即生成
			</button>
		</view>
	</view>
</template>

<script setup lang="ts">
	import { ref } from "vue";
	// import hmCopyText from '@/common/components/hm-copy-text/hm-copy-text.vue'

	const vk = uni.vk;
	const baseUrl = vk.getVuex('$app.config.staticUrl.baseUrl');

	// const bannerList = [
	// 	baseUrl + '/avatar-client/bgs/top-banner2.png',
	// 	baseUrl + '/avatar-client/bgs/top-banner1.png',
	// ]

	const templateData = {
		template_id: '',
		previewUrl: [baseUrl + '/avatar-client/images/idiom-poster.jpg'],
		shareText: '全网最齐 姓氏谐音词生成器，免费使用'
	}

	// const toPage = (i) => {
	// 	console.log(i);
	// }


	const copy = (data) => {
		console.log('idiom', data);
		uni.setClipboardData({
			data,
			success: function () {
				uni.getClipboardData({
					success: function (res) {
						uni.showToast({
							title: "复制成功",
						});
					}
				});
			},
		})
	}

	const surname = ref('杨');
	const idioms = ref([
		{ Name: "杨你一生", Index: 0 },
		{ Name: "杨杨洒洒", Index: 0 },
		{ Name: "幸福杨溢", Index: 2 },
		{ Name: "一心向杨", Index: 3 },
		{ Name: "杨枝甘露", Index: 0 },
		{ Name: "杨慕已久", Index: 0 },
		{ Name: "神采飞杨", Index: 3 },
		{ Name: "杨帆起航", Index: 0 },
		{ Name: "杨杨得亿", Index: 0 },
		{ Name: "喜气杨洋", Index: 2 }
	]);

	const surname2 = ref('刘');
	const idioms2 = ref([
		{ Name: "幸福长刘", Index: 3 },
		{ Name: "刘刘大顺", Index: 0 },
		{ Name: "富得刘油", Index: 2 },
		{ Name: "刘下幸福", Index: 0 },
		{ Name: "为你停刘", Index: 3 },
		{ Name: "唯爱停刘", Index: 3 },
		{ Name: "刘在心里", Index: 0 },
		{ Name: "风刘人物", Index: 1 },
		{ Name: "为爱停刘", Index: 3 },
		{ Name: "细水长刘", Index: 3 },
		{ Name: "刘住幸福", Index: 0 },
		{ Name: "刘住好运", Index: 0 }
	]);

	const getName = async () => {
		if (!surname.value) {
			vk.toast('请输入姓氏！');
		}
		if (surname.value.length > 1) {
			vk.toast('暂时仅支持单个字的姓氏生成哦！');
		}
		let res;
		try {
			res = await vk.callFunction({
				url: 'client/template/pub/getIdiom',
				title: '',
				data: {
					name1: surname.value,
					name2: surname2.value,
				}
			})
		} catch (err) {
			vk.toast('生成失败，请稍后再试！');
		}
		if (res && res.data) {
			idioms.value = JSON.parse(vk.myfn.HmUtils.Crypto.decrypt(res.data.name1));
			idioms2.value = JSON.parse(vk.myfn.HmUtils.Crypto.decrypt(res.data.name2));
			console.log(idioms);
		}
	}
</script>

<style lang="less" scoped>
	.home-banner {
		width: 100vw;
	}

	.container {
		background: #ffffff;
		height: 100vh;
	}

	.contents {
		display: flex;
		margin: 10rpx;
	}

	.content-container {
		display: flex;
		flex-wrap: wrap;
		max-height: 1100rpx;
		border: 1rpx solid #ffc99a;
		border-radius: 8rpx;
		justify-content: center;
		padding: 10rpx 0;
	}

	.title-tips {
		color: #989898;
		text-align: center;
		padding: 20rpx 0;
	}

	.footer {
		position: fixed;
		bottom: 10rpx;
		display: flex;
		left: 20rpx;
		width: 710rpx;
	}

	.generate-btn {
		flex: 1;
		height: 100rpx;
		margin-left: 10rpx;
		font-weight: bold;
		font-size: 32rpx;
		letter-spacing: 8;
		background: linear-gradient(90deg, #FF9E7D -2.35%, #FF6A60 100%);
		font-style: normal;
		font-weight: 500;
		color: #FFFFFF;
		border-radius: 25px;
	}

	.idiom {
		margin: 10rpx;
		font-size: 32rpx;
		color: #333333;
		position: relative;
		padding: 10rpx;
		display: inline-block;
		margin: 10rpx;
		font-size: 32rpx;
		color: #333333;
		position: relative;
		padding: 10rpx;
		display: flex;
		justify-content: center;
		align-items: center;

		&::after {
			content: '';
			position: absolute;
			left: -50%;
			top: -50%;
			width: 200%;
			border: 1rpx solid #ddd;
			height: 200%;
			transform: scale(0.5);
		}
	}

	.copy {
		margin: 0;
		padding: 0 0;
		position: absolute;
		top: 0;
		left: 0;
		width: 100%;
		height: 100%;
		display: flex;
		align-items: center;
		justify-content: center;
	}

	.inputs {
		margin: 10rpx 20rpx;
		display: flex;
		align-items: center;
		justify-content: space-between;
	}

	text {
		color: #6f6f6f;
		font-size: 28rpx;
	}

	.input-box {
		display: flex;
		justify-content: center;
		align-items: center;
		flex-direction: column;
		font-size: 32rpx;
	}

	.input {
		background: #2323;
		margin-left: 20rpx;
		border-radius: 6rpx;
		background: #cde7ff;
		padding: 12rpx 6rpx;
		text-align: center;
		font-weight: bold;
		z-index: 0;
	}
</style>